#include <iostream>

#include "FPS.hpp"
#include "Time.hpp"

FPS* FPS::instance = NULL;

FPS::FPS() {
    startTime = 0.0f;
    count = 0;
    fps = 0;
}

void FPS::update() {
    float time = Time::getInstance()->now();
    FPS::count++;

    if(time - startTime >= 1.0f) {
        fps = count;

        count = 0;
        startTime = time;
    }
}

unsigned int FPS::getFPS() {
    return fps;
}

FPS* FPS::getInstance() {
    if(instance == NULL) {
        instance = new FPS();
    }

    return instance;
}
